/**
 * 
 */
package sjtu.ist.warehouse4ws.model.file;

import java.util.ArrayList;

import sjtu.ist.warehouse4ws.jcr.RepositoryMoudl;

public class SuitImplement implements Suit{
	private ArrayList<Version> versions=null;
	private String name;
	private String path;
	SuitImplement(String name,String path)
	{
		this.name=name;
		this.path=path;
	}
	public SuitImplement(String path)
	{
		this.path=path;
	}
	
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void versionInit(RepositoryMoudl rm)
	{
		versions = new ArrayList<Version>();
		ArrayList<String> paths =rm.getVersionsPath(path);
		ArrayList<String> names = rm.getVersions(path);
		
		for (int i = 0; i < names.size(); i++) {
			versions.add(new VersionImp(names.get(i),paths.get(i)));
		}
	}
	@Override
	public Version getVersion(String name,RepositoryMoudl rm){
		if(versions==null)versionInit(rm);
		for(int i=0;i<versions.size();i++)
			if(versions.get(i).getName().equals(name))return versions.get(i);
		return null;
	}
	/*@Override
	public Views getView(String name) {
		// TODO Auto-generated method stub
		return this.getClass().getField(name);
	}*/

	@Override
	public ArrayList<Version> getVersions(RepositoryMoudl rm) {
		// TODO Auto-generated method stub
		if(versions==null)versionInit(rm);
		return versions;
	}
}
